<?PHP
defined('_XR_EXEC') or die();
/**
 * 控制器处理类 
 */
class account_Controller extends controller_user1{
	function __construct(){
		parent::__construct();
	 	$this->assign('nav','会员中心');
		$this->assign('account_menu1','3');  
	 	
		//$this->assign('account_menu2','1');
	}
	

	
	
	##################################
	/* 会员中心首页 */
	################################## 
	function index__(){
		$m_member = factory::module('member');
		$m_trans = factory::module('trans');
		$m_point = factory::module('point');
		$this->assign('rs',$m_member->getuserinfo()); 
		$this->assign('balance',$m_trans->getbalance( $m_member->getuserid() ));
		$this->assign('point',$m_point->getbalance( $m_member->getuserid() ));
		
		
	} 
	
	
	##################################
	/* 修改资料 */
	##################################
	public function info__(){
		if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST')
		{ 
			$form = format::addslash_json(json_decode( stripslashes($_POST['form']) )); 
			$db = factory::getDBO(); 
			$db->begin();
			unset($form['password']);
			$m_member = factory::module('member');
			$form['id']=$m_member->getuserid();
			//主表
		  if(!$db->update('user',array(
				'id'=>$form['id'],
				'name'=>$form['name'],
				'sex'=>$form['sex'],
				'phone'=>$form['phone'],
				'email'=>$form['email'],
			))){
				exit('操作失败！"}');
			}
			# 重新获取用户信息到session
			$_SESSION['sys_user'] = $db->loadassoc('select * from `t_user` where id="'.$form['id'].'" ');
			$db->commit();
			exit('{success:1,msg:"操作成功！"}');
		}	
		 
		 
	 	$this->assign('nav','个人资料');
		$this->assign('account_menu2','4');  
		$m_member = factory::module('member');
		$this->assign('rs',$m_member->getuserinfo());  
		
	}
	
	
	##################################
	/* 收货地址 */
	##################################
	public function deliver__(){
		
	 	$this->assign('nav','收货地址');
		$this->assign('account_menu2','5');  
		$m_member = factory::module('member');
		$this->assign('rs',$m_member->getuserinfo());   
	}
	
	
	##################################
	/* 修改密码 */
	##################################
	function pwd__(){
		if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST')
		{ 
			$_POST = format::addslash_deep($_POST);
			$db = factory::getDBO();
			$m_member = factory::module('member');
			$sql = 'select * from `#__user` where id="'.$m_member->getuserid().'" and password="'.$_POST['old_p'].'" ';
			if($db->loadassoc($sql)){
				$arr = array(
					"id" => $m_member->getuserid(),
					"password" => $_POST['new_p']
				);
				if($db->update('user',$arr)){
					exit('{success:1,msg:"修改密码成功!"}');
				}else{
					exit('系统繁忙，请稍后重试！');
				}
			}else{
				exit('操作失败，原密码输入有误！');
			} 
		}	
	 	$this->assign('nav','重置密码');
		$this->assign('account_menu2','6');
	}
	
     
	 
}
?>